fix(filesystem): still use std::filesystem::remove for folders
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Thu, 24 Apr 2025 08:07:47 +0000 (10:07 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Thu, 24 Apr 2025 09:18:11 +0000 (09:18 +0000)
this API has a way to provide an error when failing to delete a folder

we may want to know why teh folderf ailed to be deleted

QDir::rmdir does not provide any error when failing to delete a folder

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
src/libsync/filesystem.cpp

index 55d4c3c8b6b8c62ac6826f9a9711240a653e1911..3150819a33a3eb88591cba55dd709cddb3b1bc49 100644 (file)
@@ -305,7 +305,25 @@ bool FileSystem::removeRecursively(const QString &path, const std::function<void
         const auto parentPermissionsHandler = FileSystem::FilePermissionsRestore{parentFolderPath, FileSystem::FolderPermissions::ReadWrite};
         FileSystem::setFolderPermissions(path, FileSystem::FolderPermissions::ReadWrite);
         auto folderDeleteError = QString{};
-        allRemoved = FileSystem::remove(path, &folderDeleteError);
+
+        try {
+            if (!std::filesystem::remove(std::filesystem::path{fileInfo.filePath().toStdWString()})) {
+                qCWarning(lcFileSystem()) << "File is already deleted" << fileInfo.filePath();
+            }
+        }
+        catch (const std::filesystem::filesystem_error &e)
+        {
+            folderDeleteError = QString::fromLatin1(e.what());
+            qCWarning(lcFileSystem()) << e.what() << fileInfo.filePath();
+            allRemoved = false;
+        }
+        catch (...)
+        {
+            folderDeleteError = QObject::tr("Error deleting the file");
+            qCWarning(lcFileSystem()) << "Error deleting the file" << fileInfo.filePath();
+            allRemoved = false;
+        }
+
         qCInfo(lcFileSystem()) << "delete" << path;
         if (allRemoved) {
             if (onDeleted)